package com.qf.web.servlet;

import com.alibaba.fastjson.JSON;
import com.qf.pojo.GoodsType;
import com.qf.service.GoodsTypeService;
import com.qf.service.impl.GoodsTypeServiceImpl;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

@WebServlet("/goodstypeservlet")
public class GoodsTypeServlet extends BaseServlet {
    GoodsTypeService goodsTypeService = new GoodsTypeServiceImpl();

    public void goodstypelist(HttpServletRequest request, HttpServletResponse response) throws Exception{
        //查询一级分类列表
        List<GoodsType> goodsTypes= goodsTypeService.findTypeListByLevel(1);
        //把集合转换为json字符串
        Object json = JSON.toJSON(goodsTypes);
        //返回到前端
        response.setCharacterEncoding("utf-8");

        response.getWriter().print(json);

    }


}
